#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTable.Objects;

namespace UTable.Input.Text
{
    public class TextInputMapper: IInputMapper
    {
        IVisualTree _tree;

        #region IInputMapper Members

        public UTable.Objects.IVisualTree VisualTree
        {
            get
            {
                return _tree;
            }
            set
            {
                _tree = value;
            }
        }

        public System.Collections.ObjectModel.Collection<ManagedInputEventArgs> MapInput(InputEventArgs args)
        {
            TextInputEventArgs textArgs = args as TextInputEventArgs;
            if (textArgs == null || textArgs.Provider.Target == null)
            {
                return new System.Collections.ObjectModel.Collection<ManagedInputEventArgs>();
            }

            System.Collections.ObjectModel.Collection<ManagedInputEventArgs> result = new System.Collections.ObjectModel.Collection<ManagedInputEventArgs>();

			if (UTableHelper.InGlobalScope())
			{
				result.Add(new ManagedInputEventArgs(UTableHelper.GetEntity(textArgs.Provider.Target), args));
			}
			else
			{
				result.Add(new ManagedInputEventArgs(textArgs.Provider.Target, args));
			}
            return result;
        }

        public event ManagedInputEventHandler InputMapped;

        #endregion
    }
}
